import 'package:fish_redux/fish_redux.dart';
import 'action.dart';
import 'state.dart';
import '../../../app_files.dart';
import 'dart:io' show Platform;

Effect<GasInsuranceViewState> buildEffect() {
  return combineEffects(<Object, Effect<GasInsuranceViewState>>{
    Lifecycle.initState: _init,
  });
}

void _init(Action action, Context<GasInsuranceViewState> ctx) async {
  ResultData res = await CommonNetWork.getSystemConfig();
  if (res.success) {
    List data = res.data;
    Map config = data.first;
    List value = config['ConfigValue'];
    value.forEach((element) {
      if (element['Key'] == 'company') {
        ctx.state.companyName = element['Value'];
      }
      if (element['Key'] == 'mobile') {
        ctx.state.consumerPhone = element['Value'];
      }
      if (element['Key'] == 'address') {
        ctx.state.companyAddress = element['Value'];
      }
    });
  }
  ctx.dispatch(GasInsuranceViewActionCreator.onAction());
}
